package com.back.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.back.model.Comment;
import com.back.model.CommentLoadCondition;
import com.back.model.CommentPage;
import com.back.utils.Log;

@RestController
@RequestMapping("/comment")
public class CommentController {

    @PostMapping("/getResourceComment")
    public CommentPage getResourceComment(@RequestBody CommentLoadCondition commentLoadCondition) {
        Log.info(getClass(), "getResourceComment接收的资源id {}, 页码 {}", commentLoadCondition.getResourceId(),
                commentLoadCondition.getPageIndex());
        CommentPage commentPage = new CommentPage();
        commentPage.setPageIndex(commentLoadCondition.getPageIndex());
        List<Comment> comments = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            Comment comment = new Comment();
            comment.setId((commentLoadCondition.getPageIndex() - 1) * 10 + i + 1);
            comment.setUserName("用户" + ((commentLoadCondition.getPageIndex() - 1) * 10 + i + 1));
            comment.setContent(" ");
            comment.setTime("2025-06-09 12:30");
            comment.setPraise(0);
            comments.add(comment);
        }
        commentPage.setResults(comments.toArray(new Comment[0]));
        return commentPage;
    }

}